package controller.web;

import business.DaftarUser;
import business.User;
import business.Admin;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author atikahSH
 */
public class UserList extends Servlet {

    public UserList() {
        super();
        setTemplate("/WEB-INF/UserList.jsp");
    }

    @Override
    protected void process() {
      setMessage("");
        DaftarUser dib = new DaftarUser();
        if(validate_user()){
            List<User> i = (List<User>) dib.getUser(null);
            List<Admin> ii = (List<Admin>) dib.getAdmin(null);
            getRequest().setAttribute("userList", i.iterator());
        }
        else{
            try {
                getResponse().sendRedirect("UserListKosong");
            } catch (IOException ex) {
                Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex);
            }

            }
        }

    private boolean validate_user(){
        DaftarUser dib = new DaftarUser();
        int xx = dib.getJumlahUser();

        if( xx == 0){
            return false;
        }

        return true;
    }
}